package com.zxl.live.screen.ui.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.zxl.live.screen.R;

/**
 * Created by Administrator on 2017/11/13.
 */

public class WallpaperView extends ImageView {

    Animatable animatable;

    public WallpaperView(Context context) {
        super(context);
    }

    public WallpaperView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void setImageDrawable(Drawable drawable) {
        Object tag = getTag(R.mipmap.ic_launcher);
        if (null != tag && Boolean.parseBoolean(tag.toString())) {
            super.setImageDrawable(null);
            setBackgroundDrawable(drawable);
        } else {
            super.setImageDrawable(drawable);
        }
        if (Animatable.class.isInstance(drawable)) {
            this.animatable = (Animatable) drawable;
            animatable.start();
        } else {
            if (null != animatable) {
                animatable.stop();
                animatable = null;
            }
        }
    }

    @Override
    public void draw(Canvas canvas) {
        try {
            super.draw(canvas);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
